import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* 外层骨架 */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '主页', icon: 'dashboard' }
      }
    ]
  }
]

// 异步理由:不同的用户（角色），需要过滤筛选出的路由，称之为异步路由
// 有的用户可以看见测试管理、有的看不见
export const asyncRoutes = [
  {
    name: 'user',
    path: '/user',
    component: Layout,
    children: [
      {
        name: 'user',
        path: 'index',
        component: () => import('@/views/user/index'),
        meta: {
          title: '用户管理',
          icon: 'el-icon-s-custom'
        }
      }
    ]
  },
  {
    name: 'laboratory',
    path: '/laboratory',
    component: Layout,
    children: [{
      name: 'laboratory',
      path: 'index',
      component: () => import('@/views/laboratory/index'),
      meta: {
        title: '实验室',
        icon: 'el-icon-s-tools'
      }
    }]
  },
  {
    name: 'mall',
    path: '/simulationequipment',
    component: Layout,
    children: [
      {
        name: 'mallList',
        path: 'index',
        component: () => import('@/views/simulationequipment/index'),
        meta: {
          title: '仿真设备',
          icon: 'el-icon-s-platform'
        }
      }
    ]
  }
]

export const anyRoutes = { path: '*', redirect: '/404', hidden: true }

const createRouter = () =>
  new Router({
    mode: 'history',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由
}

export default router
